package vesion2.barrier;

import vesion2.main.GamePanel;
import vesion2.object.GameObject;
import vesion2.object.Point;
import vesion2.object.Rectangle;
import vesion2.object.special.Rest;
import vesion2.tank.Bullet;
import vesion2.tool.Bomb;

import java.awt.*;

public abstract class Barrier extends Rectangle implements Rest {

    public Barrier(Point left_up, int width, int height) {
        super(left_up, width, height);
    }

    public Barrier(Rectangle rectangle) {
        super(rectangle);
    }

    public Barrier(Point left_up, int width, int height, Color backColor, Image image) {
        super(left_up, width, height, backColor, image);
    }

    public Barrier(){this(new Rectangle());}

    @Override
    public void collideWithObject(GameObject object){
        if (object instanceof Bullet) {
            Bullet bullet=(Bullet)object;
            bullet.getManager().addBomb(new Bomb(this));
            isAlive=false;
            bullet.setAlive(false);
        }
    }

    public void drawImage(Graphics g, GamePanel panel){
        g.drawImage(image,left_up.getX(),left_up.getY(),width,height,panel);
    }

    @Override
    public String toString() {
        return super.toString();
    }
}
